import { createRouter, createWebHashHistory } from "vue-router"


const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: "/",
            redirect: "/Login"
        },
        {
            name: "Home",
            path: "/Home",
            redirect: "/Home/AdminIndex",
            component: () => import("../views/Admin/Index.vue"),
            children: [
                {
                    name: "AdminIndex",
                    path: "AdminIndex",
                    component: () => import("../views/Admin/AdminIndex.vue")
                },
            ]
        },
        {
            path: "/Login",
            component: () => import("../views/Login.vue"),
            meta: {
                required: true
            }
        },
    ]
})

router.beforeEach((to, from, next) => {
    if (!to.meta.required) {
        if (!sessionStorage.getItem("token")) {
            next("/Login")
        }
    }
    next()
})







export default router